home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / text / misc / AmiToVMS.lha / AmiToVMS / source / AmiToVMS.c
C/C++ Source or Header  |  1999-01-07  |  1KB  |  84 lines

  1. /* Convert an Amiga text file to a VMS text file
  2.    Writted by Gregory Eycken - ANSI/C
  3.    Using quick'n'dirty method !
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9.  
  10. void main(void)
  11. {
  12.   FILE* fin;
  13.   FILE* fout;
  14.   char filename[81];
  15.   char destname[85];
  16.   char byte;
  17.  
  18.   /* getting source filename
  19.    */
  20.   printf("Please enter filename (max. 80) : ");
  21.   gets(filename);
  22.  
  23.   /* opening source file
  24.    */
  25.   if ((fin = fopen(filename, "r")) == NULL)
  26.   {
  27.     printf("Error : can't open source file.\n");
  28.     exit(1);
  29.   }
  30.  
  31.   /* parsing destination filename
  32.    */
  33.   strcpy(destname, filename);
  34.   strcat(destname, "_VMS"); 
  35.  
  36.   /* creating destination file
  37.    */
  38.   if ((fout = fopen(destname, "w")) == NULL)
  39.   {
  40.     printf("Error : can't open destination file.\n");
  41.     fclose(fin);
  42.     exit(1);
  43.   }
  44.   
  45.   /* reading first byte
  46.    */
  47.   byte = fgetc(fin);
  48.   
  49.   while (byte != EOF)
  50.   {
  51.     /* converting Amiga -> VMS
  52.      */
  53.     if (byte == 0x0A)
  54.     {
  55.       if (fputc(0x0D, fout) != 0x0D)
  56.       {
  57.         printf("Error while writing.\n");
  58.         fclose(fin);
  59.         fclose(fout);
  60.         exit(1);
  61.       }
  62.     }
  63.   
  64.     /* writing the byte
  65.      */
  66.     if (fputc(byte, fout) != byte)
  67.     {
  68.       printf("Error while writing.\n");
  69.       fclose(fin);
  70.       fclose(fout);
  71.       exit(1);
  72.     }
  73.     
  74.     /* reading next byte
  75.      */
  76.     byte = fgetc(fin);
  77.   }
  78.   /* end of while */
  79.   
  80.   fclose(fin);
  81.   fclose(fout);
  82.   
  83.   exit(0);
  84. }